package com.base.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.po.voip.Users;
import com.base.service.UsersService;
import net.sf.json.JSONObject;

/**
 * 获取名称
 * 
 * 
 *
 */
@Controller
@RequestMapping("/admin")
public class get_Name {

	@Autowired
	private UsersService usersService; // 信息

	// 获取该代理商下的代理商名称
	@RequestMapping(value = "/getParentName", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody JSONObject getParentName(String parentid) throws Exception {
		JSONObject obj = new JSONObject();
		List<Map<String, String>> title = new ArrayList<Map<String, String>>();
		Map<String, String> map = null;
		List<Users> users = usersService.selectByUsers(new Users(parentid, 1, true));
		for (int i = 0; i < users.size(); i++) {
			map = new HashMap<String, String>();
			map.put("title", users.get(i).getUsername());
			title.add(map);
		}
		obj.put("data", title);
		return obj;
	}

	// 获取该代理商下的商家名称
	@RequestMapping(value = "/getShopName", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody JSONObject getShopName(String parentid) throws Exception {
		JSONObject obj = new JSONObject();
		List<Map<String, String>> title = new ArrayList<Map<String, String>>();
		List<Users> users = usersService.selectByUsers(new Users(parentid, 2, true));
		Map<String, String> map = null;
		for (int i = 0; i < users.size(); i++) {
			map = new HashMap<String, String>();
			map.put("title", users.get(i).getUsername());
			title.add(map);
		}
		obj.put("data", title);
		return obj;
	}
}
